package com.cysnake.easyyi.activity;

import com.cysnake.easyyi.R;
import com.cysnake.easyyi.Dao.GuaciDao;
import com.cysnake.easyyi.tools.CommonTool;
import com.cysnake.easyyi.vo.GuaVO;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class GuaInfoActivity extends Activity {
	private static final String TAG = "GuaInfoActivity";
	private GuaVO gua;
	private GuaciDao guaciDao;
	private TextView guaName;
	private TextView guaNameDec;
	private TextView guaTitle;
	private TextView guaFirst;
	private TextView guaSecond;
	private TextView guaThird;
	private TextView guaFourth;
	private TextView guaFifth;
	private TextView guaLast;
	private TextView guaComment;

	private ImageView upImage;
	private ImageView downImage;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guainfo);
		modify();

	}

	private void modify() {
		getGua();
		modifyComponent();
		displayVO();

	}

	private void getGua() {
		guaciDao = new GuaciDao(this);
		Intent intent = getIntent();
		String name = intent.getStringExtra("name");
		Log.i(TAG, "got: " + name);
		guaciDao = guaciDao.open();
		// -------------------
		gua = guaciDao.getGuaByName(name);
		guaciDao.close();
	}

	private void modifyComponent() {
		guaName = (TextView) findViewById(R.id.guainfo_textview_guaname);
		guaNameDec = (TextView) findViewById(R.id.guainfo_textview_guanamedec);
		guaTitle = (TextView) findViewById(R.id.guainfo_textview_guatitle);
		guaFirst = (TextView) findViewById(R.id.guainfo_textview_first);
		guaSecond = (TextView) findViewById(R.id.guainfo_textview_second);
		guaThird = (TextView) findViewById(R.id.guainfo_textview_third);
		guaFourth = (TextView) findViewById(R.id.guainfo_textview_fourth);
		guaFifth = (TextView) findViewById(R.id.guainfo_textview_fifth);
		guaLast = (TextView) findViewById(R.id.guainfo_textview_last);
		guaComment = (TextView) findViewById(R.id.guainfo_textview_comment);
		upImage = (ImageView) findViewById(R.id.guainfo_image_up);
		downImage = (ImageView) findViewById(R.id.guainfo_image_down);

	}

	private void displayVO() {
		String upText = gua.getNamedec().substring(0, 1);
		String downText = gua.getNamedec().substring(2, 3);
		CommonTool.setImg(upText, upImage);
		CommonTool.setImg(downText, downImage);
		guaName.setText(gua.getName());
		guaNameDec.setText(gua.getNamedec());
		guaTitle.setText(gua.getTitle());
		guaTitle.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(GuaInfoActivity.this)
						.setTitle(R.string.guainfo_title)
						.setMessage(gua.getTitledec())
						.setPositiveButton(R.string.button_comfirm, null)
						.show();

			}
		});
		guaFirst.setText(gua.getFirst());
		guaFirst.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(GuaInfoActivity.this)
						.setTitle(R.string.guainfo_title)
						.setMessage(gua.getFirstdec())
						.setPositiveButton(R.string.button_comfirm, null)
						.show();

			}
		});
		guaSecond.setText(gua.getSecond());
		guaSecond.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(GuaInfoActivity.this)
						.setTitle(R.string.guainfo_title)
						.setMessage(gua.getSeconddec())
						.setPositiveButton(R.string.button_comfirm, null)
						.show();

			}
		});
		guaThird.setText(gua.getThird());
		guaThird.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(GuaInfoActivity.this)
						.setTitle(R.string.guainfo_title)
						.setMessage(gua.getThirddec())
						.setPositiveButton(R.string.button_comfirm, null)
						.show();

			}
		});
		guaFourth.setText(gua.getFourth());
		guaFourth.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(GuaInfoActivity.this)
						.setTitle(R.string.guainfo_title)
						.setMessage(gua.getFourthdec())
						.setPositiveButton(R.string.button_comfirm, null)
						.show();

			}
		});
		guaFifth.setText(gua.getFifth());
		guaFifth.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(GuaInfoActivity.this)
						.setTitle(R.string.guainfo_title)
						.setMessage(gua.getFifthdec())
						.setPositiveButton(R.string.button_comfirm, null)
						.show();

			}
		});
		guaLast.setText(gua.getLast());
		guaLast.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(GuaInfoActivity.this)
						.setTitle(R.string.guainfo_title)
						.setMessage(gua.getLastdec())
						.setPositiveButton(R.string.button_comfirm, null)
						.show();

			}
		});
		guaComment.setText(gua.getComment());
	}


}
